package StudyCode.summary.zipfile;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ReturnListZipEntries {
	public static Collection<String> listEntries(File zip)
			throws IOException {
		return listEntries(new FileInputStream(zip));
	}

	public static Collection<String> listEntries(InputStream in)
			throws IOException {
		List<String> list = new ArrayList<String>();
		ZipInputStream zipIn = null;
		try {
			zipIn = new ZipInputStream(in);
			ZipEntry zipEntry;
			while ((zipEntry = zipIn.getNextEntry()) != null) {
				if (!zipEntry.isDirectory()) {
					list.add(zipEntry.getName());
				}
				zipIn.closeEntry();
			}
		} finally {
			if (zipIn != null) {
				zipIn.close();
			}
			in.close();
		}
		return list;
	}
}
